package control;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Requisicao;
import model.UsuarioCT;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import dao.UsuarioProjetoDAO;

public class ListarRequisicoesAction extends Action {
	
	public ActionForward execute(ActionMapping map, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws SQLException {
		
		HttpSession session = request.getSession();
		UsuarioCT usuario = (UsuarioCT)session.getAttribute("usuario");
		
		//busca as requisicoes do usuario "logado"
		Facade facade = Facade.getInstance();
		List<Requisicao> requisicoes = facade.listaRequisicoes(usuario.getUsuario());
		//envia as "requisicoes" para o JSP (foreach)
		request.setAttribute("listaRequisicoes", requisicoes);
		
		return map.findForward("listaRequisicoes");
	}
}
